package com.mrx.xbrowsersync.domain;

import com.mrx.xbrowsersync.converter.BookmarkConverter;
import com.mrx.xbrowsersync.dao.BookmarkMapper;
import com.mrx.xbrowsersync.model.dto.BookmarkResponse;
import com.mrx.xbrowsersync.model.dto.InfoResponse;
import com.mrx.xbrowsersync.model.po.BookmarkPO;
import com.mrx.xbrowsersync.model.vo.BookmarkVO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import static com.mrx.xbrowsersync.constants.BrowserSyncConstants.SYSTEM_VERSION;

/**
 * @author Mr.X
 * @since 2024-03-05 下午 7:42:22
 */
@Service
public class BrowserSyncBL {

    @Resource
    private BookmarkMapper bookmarkMapper;

    public BookmarkResponse createBookmarks(BookmarkVO vo) {
        return bookmarkMapper.initBookmarks(vo);
    }

    public BookmarkResponse getBookmarks(String id) {
        return BookmarkConverter.convert(bookmarkMapper.getBookmarkById(id), BookmarkResponse::new);
    }

    public BookmarkResponse updateBookmarks(BookmarkVO vo) {
        return BookmarkConverter.convert(bookmarkMapper.updateById(BookmarkConverter.convert(vo, BookmarkPO::new)), BookmarkResponse::new);
    }

    public BookmarkResponse getBookmarkLastUpdated(String id) {
        return BookmarkConverter.convert(bookmarkMapper.getBookmarkById(id), BookmarkResponse::new);
    }

    public BookmarkResponse getBookmarkSyncVersion(String id) {
        return BookmarkConverter.convert(bookmarkMapper.getBookmarkById(id), BookmarkResponse::new);
    }

    public InfoResponse getServiceInfo() {
        return InfoResponse.of(204800, "HelloWorld", 1, SYSTEM_VERSION);
    }
}
